<template>
  <div class="app-container">
    <!--搜索条件-->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="标书标题" prop="newsTitleShow">
        <el-input
          v-model="queryParams.newsTitleShow"
          placeholder="标书标题"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标书日期" prop="newsStarTimeShow">
        <el-date-picker
          v-model="queryParams.newsStarTimeShow"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          >
        </el-date-picker>
      </el-form-item>

      <el-form-item
        label="数据来源"
        prop="oirginId"
        label-width="100px"
        style="margin-left: -20px"
      >
        <el-select v-model="queryParams.oirginId" clearable>
          <el-option
            v-for="item in originList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <!-- 列表  -->
    <el-table :data="tableData" border style="width: 100%" align="center" size="small">
      <el-table-column prop="id" label="序号" width="60" align="center">
      </el-table-column>
      <el-table-column
        prop="originId"
        label="数据来源"
        width="120"
        align="center"
      >
      <template slot-scope="scope">{{scope.row.originId|originFilter}}</template>
      </el-table-column>

      <el-table-column
        prop="newsId"
        label="标书唯一码"
        width="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="newsTypeDes"
        label="标书类型描述"
        width="120"
        align="center"
      >
      </el-table-column>
       <el-table-column
        prop="newsTitleShow"
        label="标书标题"
        align="center"
      >
      </el-table-column>

      <!-- <el-table-column prop="newsUrl" label="标书地址" width="300" align="center">
      </el-table-column> -->
     
      <el-table-column prop="newsStarTimeShow" label="标书日期" width="120" align="center">
      </el-table-column>

      <el-table-column prop="newsZbjeShow"  label="招标预算" width="100" align="center" ></el-table-column>

      <el-table-column prop="createTime"  label="创建时间" width="150" align="center" ></el-table-column>
      <el-table-column fixed="right" label="操作" width="80" align="center">
        <template slot-scope="scope">
          <el-button @click="showInfo(scope.row)" type="text" size="small">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-row>
      <el-col :span="16" :offset="12">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.pageNum"
          :page-sizes="[2, 4, 6, 8, 10]"
          :page-size.sync="queryParams.pageSize"
          :limit.sync="queryParams.pageSize"
          layout="total, sizes, prev, pager, next"
          @pagination="getList"
          :total="total"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { pageBid } from "@/api/bid";

export default {
  name: "Bid",
  data() {
    return {
     
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        originId: undefined,
        newsTitleShow: undefined,
        newsStarTimeShow:[],
      },
      originList: [{
        value:'1',
        label:'采招网'
      },{
        value:'2',
        label:'秦源招聘网'
      }],
      tableData: [],
      
    }
  },
  filters: {
    originFilter(value){
        if (value == 1) {
        return "采招网"
      } else if (value == 2) {
        return "其他"
      } else {
        return "无"
      }
    }
    },

  methods: {
    /**
     * 根据传入的值，返回对应的中文name，
     * list: 传入的源数组
     * id： 传入的值
     * value: 源数组中为了匹配id值的字段名称
     * label: 源数组中为了匹配中文name的字段名称
     */
    getLabel(list,id,value,label){
        if(id != null && Array.isArray(list) && list.length !=0) {
          return !list.find(item => item[value] == id) ? id : list.find(item => item[value] == id)[label]
        }else{
          return id
        }
    },

    /** 查询参数列表*/
    getList() {
      this.loading = true;
      pageBid(this.queryParams).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    showInfo(row){
        var url = row.newsUrl
        window.open(url)
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    handleSizeChange(pageSize) {
      this.queryParams.pageSize = pageSize;
      this.getList();
    },
    handleCurrentChange(pageNum) {
      this.queryParams.pageNum = pageNum;
      // 这里可以添加请求数据的逻辑
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields()
      debugger;
      this.getList()
    },
  },
  
  created() {
    this.getList();
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  padding: 20px;
}

.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>